package com.jdbc.conn;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Properties;

/**
 * @author wzm
 * @create 2023-02-21 16:07
 */
//使用德鲁伊数据库连接池获取连接
public class Conn3 {
    public static void main(String[] args) throws Exception {
        //1.通过配置文件加载信息
        Properties properties = new Properties();
        properties.load(
                Conn3.class.getClassLoader()
                            .getResourceAsStream("druid.properties")
        );

        //2.通过德鲁伊工厂获取DataSource数据源
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        //3.datasouce获取连接
        Connection connection = dataSource.getConnection();
        if (connection != null) {
            System.out.println("打开连接成功");
        }

        connection.close();

    }
}
